@Inject('$log', '$rootScope', '$scope', '$state', 'personalWorkbenchService', 'ngDialogService')
class WorkbenchProcessController {
  constructor() {
    this.selectedIndex = 0;
    this.$paginationQuery();
    this.init();
  }

  $paginationQuery(type, index) {
    this.selectedIndex = index === undefined ? 0 : index;
    this.processType = type === undefined ? '1' : type;
    // 工作台状态 1代表待处理，2代表进行中 3代表已完成
    if (type === '1') {
      this.processType = '1';
    }
    if (type === '2') {
      this.processType = '2';
    }
    if (type === '3') {
      this.processType = '3';
    }
    this.$scope.$broadcast('childNotice', {
      type: this.processType,
      params: this.$scope.queryForm,
    });
  }

  $query(param) {
    if (param && param.createStartTime.$valid
      && param.createEndTime.$valid
      && param.createStartTime.$viewValue >
      param.createEndTime.$viewValue) {
      this.ngDialogService.alertError('创建时间开始时间应小于结束时间');
      return;
    }
    this.$paginationQuery(this.processType, this.selectedIndex);
  }

  $reset() {
    this.mapParams = {};
  }

  init() {
    this.tabData = [
      {
        name: '待处理',
        type: '1',
      },
      {
        name: '进行中',
        type: '2',
      },
      {
        name: '已完成',
        type: '3',
      },
    ];
  }
}

export default WorkbenchProcessController;
